package com.cqeec.dao.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import com.cqeec.dao.ManagerDao;
import com.cqeec.domain.Manager; 


public class ManagerDaoimp implements ManagerDao {
	private PreparedStatement prst=null;

	@Override
	public Manager findManagerByID(Connection conn, String managerNum) {
       Manager manager=new  Manager();
		
		String sql = "SELECT * from manager where managerNum =?";
		
		try {
			prst = conn.prepareStatement(sql);
			prst.setString(1,managerNum);
			 ResultSet rs = prst.executeQuery();
			 if(rs.next()) {
				 manager.setManagerName(rs.getString("managerName").trim());
				 manager.setManagerNum(rs.getString("managerNum").trim());
				 manager.setManagerPwd(rs.getString("managerPwd").trim());
				
				 return manager;
			 }
		
		} catch (SQLException e) { 
			JOptionPane.showMessageDialog(null, "查询失败请联系管理员", "数据错误", JOptionPane.ERROR_MESSAGE);
			return null;
		} 
		return null;
	}

	@Override
	public void upateManagerByManagerName(Connection connection, Manager manager) throws Exception {
		
		String sql= "UPDATE manager SET managerPwd = ? WHERE managerNum=?";
		PreparedStatement prst = connection.prepareStatement(sql);
		prst.setString(1, manager.getManagerPwd());
		prst.setString(2, manager.getManagerName());
		prst.executeQuery(); 
		
	}


	
}
